#include "lsm6dso_reg.h"
#include <stddef.h>

/**
 * @brief Read register from lsm6dso
 * 
 * @param lsm6dso_handle {i2c_master_dev_handle_t} created by i2c_master_bus_add_device()
 * @param reg            register to read
 * @param data           pointer to buffer that store the read data
 * @param len            number of consecutive register to read
 * @retval               {esp_err_t}
 */
esp_err_t lsm6dso_read_reg(const i2c_master_dev_handle_t lsm6dso_handle, 
                            uint8_t *reg, uint8_t *data, uint16_t len)
{
    return i2c_master_transmit_receive(lsm6dso_handle, reg, 1, data, len, -1);
}

/**
 * @brief Write register from lsm6dso
 * 
 * @param lsm6dso_handle {i2c_master_dev_handle_t} created by i2c_master_bus_add_device()
 * @param reg            register to write
 * @param data           pointer to buffer that store the write data
 * @retval               {esp_err_t}
 */
esp_err_t lsm6dso_write_reg(const i2c_master_dev_handle_t lsm6dso_handle, 
                            uint8_t *reg, uint8_t *data)
{
    uint8_t buffer[2];//数组变量本身就是指向其起始单元的一个指针
    buffer[0] = *reg;
    buffer[1] = *data;
    return i2c_master_transmit(lsm6dso_handle, buffer, 2, -1);
}